import html


# html.escape 将特殊字符“&”、“<”和“>”替换为 HTML 安全序列。如果可选标志 quote 为 true（默认值），则引号字符、双引号 (") 和单引号 (') 字符也会被翻译。
# attrs.items()  参数名
def make_element(name, value, **attrs):
    keyvals = [' %s="%s"' % item for item in attrs.items()]
    attr_str = ''.join(keyvals)
    element = '<{name}{attrs}>{value}</{name}>'.format(
        name=name,
        attrs=attr_str,
        value=html.escape(value))
    return element


# Example
# Creates '<item size="large" quantity="6">Albatross</item>'
print(make_element('item', 'Albatross', size='large', quantity=6))

# Creates '<p>&lt;spam&gt;</p>'
print(make_element('p', '<spam>'))


def anyargs(*args, **kwargs):
    print(args)  # A tuple
    print(kwargs)  # A dict


# 将强制关键字参数放到某个参数或者单个后面就能达到这种效果
def recv(maxsize, *, block) -> int:
    'Receives a message'
    pass


recv(1024, True)  # TypeError
recv(1024, block=True)  # Ok
